package com.ramesh.fragmenttabhostdemo;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CountriesFragment extends Fragment{

	private TextView text;

	public CountriesFragment() {
		// TODO Auto-generated constructor stub

	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View v = LayoutInflater.from(getActivity()).inflate(R.layout.countries_page,
				null);
		//text = (TextView) v.findViewById(R.id.text);
		if (getArguments() != null) {
			//
			try {
				String value = getArguments().getString("key");
				///text.setText("Current Tab is: " + value);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return v;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		
	    LinearLayout linearLayout1 = (LinearLayout) getView().findViewById(R.id.countries_scroll_view_layout);
        ImageView image = new ImageView(getActivity());
        image.setBackgroundResource(R.drawable.a1);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        lp.setMargins(2, 2, 2, 2);
        image.setLayoutParams(lp);
        linearLayout1.addView(image);
        image.setClickable(true);
        image.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
				FragmentManager fragmentManager = getFragmentManager();
				FragmentTransaction fragmentTransaction = fragmentManager
						.beginTransaction();

				CountryFragment countriyFragment = new CountryFragment();
				fragmentTransaction.replace(R.id.realtabcontent, countriyFragment);
				//provide the fragment ID of your first fragment which you have given in
				//fragment_layout_example.xml file in place of first argument
				fragmentTransaction.addToBackStack(null);
				fragmentTransaction.commit();
            }
        });
        
        
        
        
        
         image = new ImageView(getActivity());
        image.setBackgroundResource(R.drawable.a2);
        linearLayout1.addView(image);
         image = new ImageView(getActivity());
        image.setBackgroundResource(R.drawable.a3);
        linearLayout1.addView(image);
         image = new ImageView(getActivity());
        image.setBackgroundResource(R.drawable.a4);
        linearLayout1.addView(image);
         image = new ImageView(getActivity());
        image.setBackgroundResource(R.drawable.a5);
        linearLayout1.addView(image);
         image = new ImageView(getActivity());
        image.setBackgroundResource(R.drawable.a6);
        linearLayout1.addView(image);
	}
	//
}
